/**
    Copyright (C) 2011  Alexander Vollmer

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.jefb.entity;

import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

@Entity
@Table(name = "CV_FILE_TOKEN")
public class FileTokenEntity implements Serializable {

	private static final long serialVersionUID = 1L;
	private Long id;
	private Boolean transmitted;
	private Long size;
	private Long offset;
	private byte[] data;

	private DestinationEntity destination;
	private FileEntity file;

	public FileTokenEntity() {
		super();
	}

	public FileTokenEntity(Long size, Long offset) {
		super();
		this.size = size;
		this.offset = offset;
	}

	public FileTokenEntity(Long size, Long offset, byte[] data) {
		super();
		this.size = size;
		this.offset = offset;
		this.data = data;
	}
	
	public String toString(){
		return "|Length:"+size;
	}

	@Id
	@Column(name = "ID")
	@GeneratedValue
	public Long getId() {
		return id;
	}

	@Column(name = "TRANSMITTED", columnDefinition = "SMALLINT NOT NULL DEFAULT 0")
	public Boolean getTransmitted() {
		return transmitted;
	}

	@Column(name = "SIZE", nullable = false)
	public Long getSize() {
		return size;
	}

	@Column(name = "OFFSET", nullable = false)
	public Long getOffset() {
		return offset;
	}

	@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
	@JoinColumn(name = "DESTINATION_ID")
	public DestinationEntity getDestination() {
		return destination;
	}

	@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
	@JoinColumn(name = "FILE_ID")
	public FileEntity getFile() {
		return file;
	}

	@Transient
	public byte[] getData() {
		return data;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public void setTransmitted(Boolean transmitted) {
		this.transmitted = transmitted;
	}

	public void setSize(Long size) {
		this.size = size;
	}

	public void setOffset(Long offset) {
		this.offset = offset;
	}

	public void setData(byte[] data) {
		this.data = data;
	}

	public void setDestination(DestinationEntity destination) {
		this.destination = destination;
	}

	public void setFile(FileEntity file) {
		this.file = file;
	}

}
